package com.jn.jetpack.views;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jn.jetpack.R;
import com.jn.jetpack.base.BaseActivity;
import com.jn.jetpack.contract.NewsContract;
import com.jn.jetpack.entity.News;
import com.jn.jetpack.presenter.NewsPresenter;
import com.jn.jetpack.utils.LogUtils;

public class NewsActivity extends BaseActivity implements NewsContract.INewsView {

    private TextView mText1;
    private TextView mText2;
    private TextView mText3;
    private ImageView mImage1;
    private ImageView mImage2;

    private NewsContract.INewsPresenter mPresenter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_news;
    }

    @Override
    public void init() {
        mPresenter = new NewsPresenter(this, this);
        getLifecycle().addObserver(mPresenter);
        mText1 = findViewById(R.id.text1);
        mText2 = findViewById(R.id.text2);
        mText3 = findViewById(R.id.text3);
        mImage1 = findViewById(R.id.image1);
        mImage2 = findViewById(R.id.image2);
        //mPresenter.getData();
    }

    @Override
    public void onHttpLoading(boolean loading) {

    }

    @Override
    public void onHttpFail(String... msg) {
        showToast(msg.length > 0 ? msg[0] : "");
    }

    @Override
    public void onHttpTimeout() {

    }

    @Override
    public void onHttpTokenExpiration() {

    }

    @Override
    public void showData(News data) {
        LogUtils.d("asdf", "===" + data.toString());
        mText1.setText(data.getData().getDate());
        mText2.setText(data.getData().getWeiyu());
        StringBuffer sb = new StringBuffer();
        for (String s : data.getData().getNews()) {
            sb.append(s).append("\n\n");
        }
        mText3.setText(sb.toString());
        Glide.with(this).load(data.getData().getHead_image()).into(mImage1);
    }
}